﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FormInputProject.Models;
using FormInputProject.Services;
using WebMatrix.WebData;

namespace FormInputProject.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {

            return View();
        }

        [HttpPost]
        public ActionResult Index(User user)
        {
            UserBaseService userService = new UserBaseService();
            int result = userService.UserLogin(user);

            if (ModelState.IsValid && result == 1)
            {
                Session["UserName"] = user.UserName;
                return Redirect("/Record/FormRecordInput");
            }

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "你的应用程序说明页。";
            
            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "你的联系方式页。";

            return View();
        }

        #region 帮助程序
        private ActionResult RedirectToLocal(string returnUrl)
        {
            if (Url.IsLocalUrl(returnUrl))
            {
                return Redirect(returnUrl);
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }
        }
        #endregion
    }
}
